#!/bin/bash

set -e
set -o pipefail

CONFIGURE_DIR=$(dirname "$0")
cd "${CONFIGURE_DIR}"

if [ ! -f "/home/jenkins/tensorflow26/.env/bin/activate" ];then
  echo "No venv for tensorflow2.x installed, skip CI build"
  exit 0
fi

source /home/jenkins/tensorflow26/.env/bin/activate

if [ "$1x" != "x" ];then
  python_version=$1
fi

if [ -z "$python_version" ]; then
  if [ "${OS_TYPE}" = "centos_aarch64" ]; then
    PYTHON_BIN_PATH=$(which python3.7)
  else
    PYTHON_BIN_PATH=$(which python3.9)
  fi
else
  PYTHON_BIN_PATH=$(which $python_version)
fi

export ADAPTER_TARGET_PYTHON_PATH="$PYTHON_BIN_PATH"
export ASCEND_INSTALLED_PATH="$ASCEND_HOME_PATH"

echo "ADAPTER_TARGET_PYTHON_PATH set to $ADAPTER_TARGET_PYTHON_PATH"

"$PYTHON_BIN_PATH" "configure.py" "$@"

echo "Configuration finished"

rm -rf build
mkdir build
cd build
cmake -DASCEND_CI_LIMITED_PY37_ENABLE=ON ..
make -j8

deactivate
